package me.zk.practice1.s;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangkai
 * @date 2023/7/13 11:32
 */
public class LS_Offer_35 {
    Map<Node, Node> cacheMap = new HashMap<>();
    public Node copyRandomList(Node head) {
        if (head == null) {
            return null;
        }
        if (!cacheMap.containsKey(head)) {
            Node newNode = new Node(head.val);
            cacheMap.put(head,newNode);
            newNode.next = copyRandomList(head.next);
            newNode.random = copyRandomList(head.random);
        }
        return cacheMap.get(head);

    }
}
